/*
 * Copyright (C) 2011, EADS France
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 */
package xowl.gmi.view;

import java.util.HashMap;
import java.util.Map;
import xowl.gmi.environment.Locale;

/**
 *
 * @author Laurent
 */
public class Libraries extends CollapsePanel {
    private javax.swing.JTabbedPane container;
    private Map<String, javax.swing.JPanel> tabs;
    
    public Libraries(Locale locale) {
        super(locale.winLibraries);
        container = new javax.swing.JTabbedPane();
        tabs = new HashMap<>();
        this.setContent(container);
    }
    
    public void addLibray(String title) {
        javax.swing.JPanel panel = new javax.swing.JPanel();
        panel.setOpaque(true);
        panel.setLayout(new javax.swing.BoxLayout(panel, javax.swing.BoxLayout.Y_AXIS));
        javax.swing.JScrollPane scroll = new javax.swing.JScrollPane(panel, javax.swing.JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        container.add(title, scroll);
        tabs.put(title, panel);
    }
    
    public void addToolboxElement(String lib, ToolboxElement elem) {
        elem.setAlignmentX(java.awt.Component.LEFT_ALIGNMENT);
        tabs.get(lib).add(elem);
        this.revalidate();
        this.repaint();
    }
    public void removeToolboxElement(String lib, ToolboxElement elem) {
        tabs.get(lib).remove(elem);
        this.revalidate();
        this.repaint();
    }
}
